package com.c2soft.nepalcmx.controller;

import java.text.ParseException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.c2soft.nepalcmx.command.AccountDetailCommand;
import com.c2soft.nepalcmx.command.ConfirmTradeCommand;
import com.c2soft.nepalcmx.command.TradeBookCommand;
import com.c2soft.nepalcmx.command.TradeBookCommand;

import com.c2soft.nepalcmx.services.TradeBookService;
import com.c2soft.nepalcmx.util.JsonUtil;

@Log4j2
@Controller
public class TradeBookController {
	
	@Autowired
	private TradeBookService tradeBookService;
	
	
	@RequestMapping(value = "/tradeBook",method=RequestMethod.GET, headers = "Accept=application/json")
	
	public @ResponseBody List<TradeBookCommand> getTrades(@RequestParam("userId") String userId) {
		
	List<TradeBookCommand> tradeBookEntries=tradeBookService.getTradeBookEntriesForUser(userId);
	return tradeBookEntries;
	}
	
@RequestMapping(value = "/tradeBook1",method=RequestMethod.GET, headers = "Accept=application/json")
	
	public @ResponseBody List<TradeBookCommand> getTrades1(@RequestParam("brokeId") String brokerId) {
		
	List<TradeBookCommand> tradeBookEntries=tradeBookService.getTradeBookEntriesForBroker(brokerId);
	return tradeBookEntries;
	}

@RequestMapping(value = "/tradeBook2",method=RequestMethod.GET, headers = "Accept=application/json")

public @ResponseBody List<TradeBookCommand> getTrades2() {
List<TradeBookCommand> tradeBookEntries=tradeBookService.getTradeBookEntriesForUsers1();
	return tradeBookEntries;
}

@RequestMapping(value = "/prevtradeBook",method=RequestMethod.GET, headers = "Accept=application/json")

public @ResponseBody List<TradeBookCommand> getPrevTradeBook(@RequestParam("userId") String userId) {
	
	List<TradeBookCommand> tradeBookEntries=tradeBookService.getPrevTradeBookEntriesForUser(userId);
	return tradeBookEntries;
}

@RequestMapping(value = "/prevtradeBook1",method=RequestMethod.GET, headers = "Accept=application/json")

public @ResponseBody List<TradeBookCommand> getPrevTradeBook1(@RequestParam("brokeId") String brokerId) {
	List<TradeBookCommand> tradeBookEntries=tradeBookService.getPrevTradeBookEntriesForBrokers(brokerId);
	return tradeBookEntries;
}

@RequestMapping(value = "/prevtradeBook2",method=RequestMethod.GET, headers = "Accept=application/json")

public @ResponseBody List<TradeBookCommand> getPrevTradeBook2() {
	List<TradeBookCommand> tradeBookEntries=tradeBookService.getPrevTradeBookEntriesForUsers1();
return tradeBookEntries;
}


@RequestMapping(value = "/tradeConform", method={RequestMethod.POST,RequestMethod.GET}, headers = "Accept=application/json")
public @ResponseBody List<TradeBookCommand> tradeConform( @RequestBody String json,HttpServletRequest req) throws ParseException {
	String userId=(String) req.getSession().getAttribute("UsrId");
	ConfirmTradeCommand confirmTrade= (ConfirmTradeCommand) JsonUtil.fromJson(json,ConfirmTradeCommand.class);
   List<TradeBookCommand> confirmtradeBookEntries=tradeBookService.getTradeBookEntries(userId, confirmTrade);
    return confirmtradeBookEntries;
    }



}
